package org.wzl._360mallbackend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.wzl._360mallbackend.dao.CommodityDao;
import org.wzl._360mallbackend.dto.CommodityDTO;
import org.wzl._360mallbackend.utils.Response;

import java.util.Objects;

@RestController
@RequestMapping("/commodity")
public class CommodityController {

    @Autowired
    private CommodityDao commodityDao;

    @GetMapping("/getById")
    public Response getById(@RequestParam("id") Integer id) {
        CommodityDTO commodityDTO = commodityDao.getById(id);
        if (Objects.isNull(commodityDTO)) {
            return Response.fail();
        } else {
            return Response.ok().putData("commodity" , commodityDTO);
        }
    }

}
